package com.ruoyi.project.bill.controller;


import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.bill.domain.BillAction;
import com.ruoyi.project.bill.service.IBillActionService;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 单据动作Controller
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@RestController
@RequestMapping("/action")
@Slf4j
public class BillActionController extends BaseController
{
    @Autowired
    private IBillActionService billActionService;

    /**
     * 查询单据动作列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BillAction billAction)
    {

        startPage();
        List<BillAction> list = billActionService.selectBillActionList(billAction);
        return getDataTable(list);
    }

    /**
     * 导出单据动作列表
     */
    @Log(title = "单据动作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillAction billAction)
    {

        List<BillAction> list = billActionService.selectBillActionList(billAction);
        ExcelUtil<BillAction> util = new ExcelUtil<BillAction>(BillAction.class);
        util.exportExcel(response, list, "单据动作数据");
    }

    /**
     * 获取单据动作详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(billActionService.selectBillActionById(id));
    }

    /**
     * 新增单据动作
     */
    @Log(title = "单据动作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillAction billAction)
    {
        String msg = billActionService.insertBillAction(billAction);
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }

    /**
     * 修改单据动作
     */
    @Log(title = "单据动作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillAction billAction)
    {
        String msg = billActionService.updateBillAction(billAction);
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }

    /**
     * 删除单据动作
     */
    @Log(title = "单据动作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        String msg = (billActionService.deleteBillActionByIds(ids));
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }


}
